package com.line.service;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.config.dao.ChargeConfigDao;
import com.config.dao.EquipmentDao;
import com.config.dao.LineConfigDao;
import com.config.dao.ShiftConfigDao;
import com.config.entity.Equipment;
import com.config.entity.LineConfig;
import com.config.entity.ShiftConfig;
import com.data.dao.ChargeDayDao;
import com.data.dao.ChargeMinDao;
import com.data.dao.ChargeMonthDao;
import com.data.dao.ChargeShiftDao;
import com.data.dao.ChargeWeekDao;
import com.data.dao.StateDayDao;
import com.data.dao.StateMinDao;
import com.data.dao.StateMonthDao;
import com.data.dao.StateWeekDao;
import com.data.entity.ChargeDay;
import com.data.entity.ChargeMin;
import com.data.entity.ChargeMonth;
import com.data.entity.ChargeShift;
import com.data.entity.ChargeWeek;
import com.data.entity.StateDay;
import com.data.entity.StateMin;
import com.data.entity.StateMonth;
import com.data.entity.StateWeek;
import com.line.dao.LineDao;

@Service("lineService")
public class LineServiceImpl implements LineService{
	@Resource(name="lineDao")
	private LineDao lineDao;
	@Resource(name="lineConfigDao")
	private LineConfigDao lineConfigDao;
	@Resource(name="equipmentDao")
	private  EquipmentDao equipmentDao;
	@Resource(name="shiftConfigDao")
	private ShiftConfigDao shiftConfigDao;
	@Resource(name = "chargeConfigDao")
	private ChargeConfigDao chargeConfigDao;
	@Resource(name="chargeMinDao")
	private ChargeMinDao chargeMinDao;
	@Resource(name="chargeShiftDao")
	private ChargeShiftDao chargeShiftDao;
	@Resource(name="chargeDayDao")
	private ChargeDayDao chargeDayDao;
	@Resource(name="chargeWeekDao")
	private ChargeWeekDao chargeWeekDao;
	@Resource(name="chargeMonthDao")
	private ChargeMonthDao chargeMonthDao;
	@Resource(name="stateMinDao")
	private StateMinDao stateMinDao;
	@Resource(name="stateDayDao")
	private StateDayDao stateDayDao;
	@Resource(name="stateWeekDao")
	private StateWeekDao stateWeekDao;
	@Resource(name="stateMonthDao")
	private StateMonthDao stateMonthDao;
	/**
	 * 整线每日电度电费计算
	 * @param lineId
	 * @param belongDate
	 * @param model
	 */
	@Override
	public void getLineElectricityDayData(int lineId, String belongDate, Map<String, Object> model) {
		int totalElectric=0;int machineElectric=0;
		StringBuffer shiftMode=new StringBuffer();//排班模式
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
		List<String> shifts=new ArrayList<String>();//增加“全天”的班次
		List<String> pieLegend=new ArrayList<String>();//饼图图例
		List<Integer> shiftRelativeComp=new ArrayList<Integer>();//班次电度
		List<Integer> hourRelativeComp=new ArrayList<Integer>();//每小时电度
		List<Map<String,Object>> electricityPie=new ArrayList<Map<String,Object>>();//饼图电度
		List<Map<String,Object>> chargePie=new ArrayList<Map<String,Object>>();//饼图电费
		LineConfig linec=lineConfigDao.get(lineId);
		String lineName=linec.getName()+"("+linec.getLinesNo()+")";
		//小时字符串
		List<String> hours=Arrays.asList(new String[]{
				"00:30", "01:00", "01:30", "02:00", "02:30", "03:00", "03:30", "04:00", "04:30", "05:00", "05:30", "06:00", "06:30", "07:00", "07:30", "08:00", 
				"08:30", "09:00", "09:30", "10:00", "10:30", "11:00", "11:30", "12:00","12:30", "13:00", "13:30", "14:00", "14:30", "15:00", "15:30", "16:00",
				"16:30", "17:00", "17:30", "18:00", "18:30", "19:00", "19:30", "20:00", "20:30", "21:00", "21:30", "22:00", "22:30", "23:00", "23:30", "24:00"});//getXAxis();
		ShiftConfig  config=shiftConfigDao.findShiftsByLine(lineId, belongDate);//班制
		//班次电度
		if(config!=null){
			List<ShiftConfig> useShifts=shiftConfigDao.findByShiftsId(config.getId());
			if(useShifts.size()!=0){
				for(ShiftConfig s:useShifts){
					shiftMode.append(s.getShiftName()+" ");
					shifts.add(s.getShiftName());
					ChargeShift cs=chargeShiftDao.getShiftElectricAndChargeByDate(lineId, s.getId(), belongDate,"Y");
					if(cs!=null){
						shiftRelativeComp.add(cs.getRelativeComp().intValue());
					}
				}
				//饼图电度电费
				List<ChargeDay>days=chargeDayDao.getChargeDayIdAndDate(lineId, belongDate, "Y");
				if(days.size()!=0){
					for(ChargeDay day:days){
						pieLegend.add(day.getChargeName()+"电度");
						pieLegend.add(day.getChargeName()+"电费");
						totalElectric+=day.getRelativeComp();
						Map<String,Object> electricMap=new HashMap<String,Object>();
						Map<String,Object> chargeMap=new HashMap<String,Object>();
						electricMap.put("name", day.getChargeName()+"电度");
						electricMap.put("value", day.getRelativeComp());
						electricityPie.add(electricMap);
						
						chargeMap.put("name", day.getChargeName()+"电费");
						chargeMap.put("value", day.getCharge());
						chargePie.add(chargeMap);
					}
				}else{
					Map<String,Object> electricMap=new HashMap<String,Object>();
					Map<String,Object> chargeMap=new HashMap<String,Object>();
					electricMap.put("name", "电度");
					electricMap.put("value", 0);
					electricityPie.add(electricMap);
					
					chargeMap.put("name", "电费");
					chargeMap.put("value", 0);
					chargePie.add(chargeMap);
				}
				shifts.add("一天");
				shiftRelativeComp.add((int)totalElectric);
				//小时电度
				List<ChargeMin> mins=chargeMinDao.getChargeMinsByDay(lineId, belongDate, "Y");
				int i = 0;
				for(String xt:hours){
					int tempCharge = 0;
					if(i<mins.size()){
						ChargeMin cm = mins.get(i);
						if(sdf.format(cm.getBelongTime()).equals("00:00")){
							i++;
						}else{
							while(sdf.format(cm.getBelongTime()).equals(xt)){
								tempCharge = cm.getRelativeComp().intValue();
								i++;
								break;
							}
						}
					}
					if(tempCharge!=0.0){
						hourRelativeComp.add(tempCharge);
					}else{
						hourRelativeComp.add(0);
					}
				}
				
				//计算设备加和电度和损失电度
				List<Equipment> equs=equipmentDao.listByLine(lineId);
				if(equs.size()!=0){
					for(Equipment e:equs){
						List<ChargeDay>chargesdays=chargeDayDao.getChargeDayIdAndDate(e.getId(), belongDate, "N");
						if(chargesdays.size()!=0){
							for(ChargeDay c:chargesdays){
								machineElectric+=c.getRelativeComp();
							}
						}
					}
				}
				model.put("success", true);
			}else{
				model.put("success", false);
				model.put("msg", "没有建立班次!");
			}
		}else{
			model.put("success", false);
			model.put("msg", "没有建立班次!");
		}
		model.put("lineName", lineName);
		model.put("belongDate", belongDate);
		model.put("totalElectric", totalElectric+"度");
		model.put("machineElectric", machineElectric+"度");
		model.put("lossElectric", totalElectric-machineElectric+"度");
		model.put("shifts", shifts);
		model.put("shiftMode", shiftMode);
		model.put("hours", hours);
		model.put("pieLegend", pieLegend);
		model.put("shiftRelativeComp", shiftRelativeComp);
		model.put("hourRelativeComp", hourRelativeComp);
		model.put("electricityPie", electricityPie);
		model.put("chargePie", chargePie);
	}
	/**
	 * 整线日综合电度电费计算
	 * @param lineId
	 * @param startDate
	 * @param endDate
	 * @param model
	 */
	@Override
	public void getLineElectricityCompexData(int lineId, String startDate, String endDate, Map<String, Object> model) {
		int totalElectric=0;int machineElectric=0;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		List<String> legType=new ArrayList<String>();//电费电度峰谷值
		List<String> legBar=new ArrayList<String>();//电度峰谷值
		List<String> shiftNames=new ArrayList<String>();//班次
		List<String> days=new ArrayList<String>();//横轴天数
		List<String> everyday=new ArrayList<String>();//横轴天数
		List<Map<String,Object>> electricityBar=new ArrayList<Map<String,Object>>();//每日电度
		List<Map<String,Object>> groupElectricityPie=new ArrayList<Map<String,Object>>();//班次电度
		List<Map<String,Object>> groupChargePie=new ArrayList<Map<String,Object>>();//班次电费
		List<Map<String,Object>> electricityPie=new ArrayList<Map<String,Object>>();//饼图状态电度
		List<Map<String,Object>> chargePie=new ArrayList<Map<String,Object>>();//饼图状态电费
		LineConfig linec=lineConfigDao.get(lineId);
		String lineName=linec.getName()+"("+linec.getLinesNo()+")";
		try {
			Calendar start=Calendar.getInstance();
			Calendar end=(Calendar) start.clone();
			start.setTime(sdf.parse(startDate));
			end.setTime(sdf.parse(endDate));
			int aeraDay=(int) ((end.getTimeInMillis()-start.getTimeInMillis())/(24*3600*1000L));
			ShiftConfig shift=shiftConfigDao.findShiftsByTime(lineId, startDate, endDate);
			List<ChargeDay> chargec=chargeDayDao.getDistricChargeName(lineId, startDate, endDate, "Y");
			if(shift!=null){
				List<ShiftConfig> configs=shiftConfigDao.findByShiftsId(shift.getId());
				if(configs.size()!=0){
				 //折线图每日电度
					if(chargec.size()!=0){
						for(ChargeDay c:chargec){
							legBar.add(c.getChargeName()+"电度");
							List<Integer> dayElecricity=new  ArrayList<Integer>();//每天电度
							for(int day=0;day<=aeraDay;day++){
								String date=sdf.format(new Date(start.getTimeInMillis()+day*24*60*60*1000L));
							    ChargeDay chargeday=chargeDayDao.getChargeDayByDate(lineId, c.getChargeName(), date, "Y");
							    if(chargeday!=null){
							    	totalElectric+=chargeday.getRelativeComp();
//									Map<String, Object> dayElecricity=new HashMap<String, Object>();
//									dayElecricity.put("name", c.getChargeName());
//									dayElecricity.put("value", chargeday.getRelativeComp());
//									electricityBar.add(dayElecricity);
							    	dayElecricity.add(chargeday.getRelativeComp().intValue());
								}
							    days.add(new SimpleDateFormat("M.d").format(sdf.parse(date)));
							}
							
							Map<String, Object> dayEle=new HashMap<String, Object>();
							dayEle.put("name", c.getChargeName()+"电度");
							dayEle.put("value", dayElecricity);
							electricityBar.add(dayEle);
						//饼图电费电度数据
						legType.add(c.getChargeName()+"电度");
						legType.add(c.getChargeName()+"电费");
						ChargeDay chargeelecricity=chargeDayDao.getCompAndChargeByType(lineId, startDate, endDate, c.getChargeName(), "Y");
						if(chargeelecricity!=null){
							Map<String, Object> elecricitys=new HashMap<String, Object>();
							elecricitys.put("name", c.getChargeName()+"电度");
							elecricitys.put("value", chargeelecricity.getRelativeComp());
							electricityPie.add(elecricitys);
							Map<String, Object> charges=new HashMap<String, Object>();
							charges.put("name", c.getChargeName()+"电费");
							charges.put("value", chargeelecricity.getCharge());
							chargePie.add(charges);
						}
					}
				}
				//班次电费电度数据
				for(ShiftConfig c:configs ){
					shiftNames.add(c.getShiftName());
					ChargeShift cshift=chargeShiftDao.getShiftElectricAndChargeByAreaDate(lineId, c.getId(), startDate, endDate, "Y");
					if(cshift!=null){
						Map<String, Object> groupelecricitys=new HashMap<String, Object>();
						groupelecricitys.put("name", c.getShiftName());
						groupelecricitys.put("value",cshift.getRelativeComp());
						groupElectricityPie.add(groupelecricitys);
						Map<String, Object> groupcharges=new HashMap<String, Object>();
						groupcharges.put("name", c.getShiftName());
						groupcharges.put("value",cshift.getCharge());
						groupChargePie.add(groupcharges);
					}
				}
			//设备加和电度和损失电度
			List<Equipment> equs=equipmentDao.listByLine(lineId);
			if(equs.size()!=0){
				for(Equipment e:equs){
					ChargeDay chargesdays=chargeDayDao.getCompAndChargeByType(e.getId(), startDate, endDate, "", "N");
					if(chargesdays!=null){
						machineElectric+=chargesdays.getRelativeComp();
					}
				}
			}
			//日期去重
		    for(String s:days){
		    	 if(Collections.frequency(everyday, s) < 1) everyday.add(s);
		    }
			model.put("success", true);
		}else{
			model.put("success", false);
			model.put("msg", "查询时间段内班次为空，请重新选择时间。");
		}
	}else{
		model.put("success", false);
		model.put("msg", "查询时间段跨班次,请重新选择时间。");
		}
	} catch (ParseException e) {
		e.printStackTrace();
	}
		model.put("lineName", lineName);
		model.put("startDate", startDate);
		model.put("endDate", endDate);
		model.put("totalElectric", totalElectric+"度");
		model.put("machineElectric", machineElectric+"度");
		model.put("lossElectric", totalElectric-machineElectric+"度");
		model.put("shiftNames", shiftNames);
		model.put("everyday", everyday);
		model.put("electricityBar", electricityBar);
		model.put("legBar", legBar);
		model.put("legType", legType);
		model.put("electricityPie", electricityPie);
		model.put("chargePie", chargePie);
		model.put("groupElectricityPie", groupElectricityPie);
		model.put("groupChargePie", groupChargePie);
 }
	/**
	 * 整线周电度电费统计
	 * @param lineId
	 * @param belongYear
	 * @param startWeek
	 * @param endWeek
	 * @param model
	 */
	@Override
	public void getLineElecricityWeekData(int lineId, int belongYear,int startWeek, int endWeek, Map<String, Object> model) {
		int totalElectric=0;int machineElectric=0;
		List<String> legType=new ArrayList<String>();//电度电费峰谷值
		List<String> barLegend=new ArrayList<String>();//legend电度，不同峰谷值
		List<String> weeks=new ArrayList<String>();//横轴周数
		List<Map<String,Object>> chargeBar=new ArrayList<Map<String,Object>>();//每周不同峰谷值电费
		List<Map<String,Object>> electricityPie=new ArrayList<Map<String,Object>>();//饼图状态电度
		List<Map<String,Object>> chargePie=new ArrayList<Map<String,Object>>();//饼图状态电费
		LineConfig linec=lineConfigDao.get(lineId);
		String lineName=linec.getName()+"("+linec.getLinesNo()+")";
		barLegend.add("电度");
		List<Integer> weekElecricity=new  ArrayList<Integer>();//每周电度
		Map<String, Object> weekcharges=new HashMap<String, Object>();//每周电度电费
		//每周电度
		for(int week=startWeek;week<=endWeek;week++){
			weeks.add(week+"周");
			ChargeWeek cweek=chargeWeekDao.getCompByDate(lineId, belongYear, week, "Y");
			if(cweek!=null){
				weekElecricity.add(cweek.getRelativeComp().intValue());
			}
		}
		
		weekcharges.put("name", "电度");
		weekcharges.put("value", weekElecricity);
		chargeBar.add(weekcharges);
		
		List<ChargeWeek> chargec=chargeWeekDao.getDistinctChargeName(belongYear, startWeek, endWeek);
		if(chargec.size()!=0){
	        for(ChargeWeek chargew:chargec){
	        	List<Integer> weekCharge=new  ArrayList<Integer>();//每周电费
	        	//每周各峰谷值电费
	        	barLegend.add(chargew.getChargeName()+"电费");
				for(int week=startWeek;week<=endWeek;week++){
					weekcharges=new HashMap<String, Object>();
					ChargeWeek cweek=chargeWeekDao.getChargeWeekByDate(lineId, belongYear, week, chargew.getChargeName(), "Y");
					if(cweek!=null){
//						weekcharges.put("name", chargew.getChargeName()+"电费");
//						weekcharges.put("value", cweek.getCharge());
//						chargeBar.add(weekcharges);
						weekCharge.add(cweek.getCharge().intValue());
					}
				}
				weekcharges.put("name", chargew.getChargeName()+"电费");
				weekcharges.put("value", weekCharge);
				chargeBar.add(weekcharges);
				
				//饼图电费电度数据
				legType.add(chargew.getChargeName()+"电度");
				legType.add(chargew.getChargeName()+"电费");
				ChargeWeek weekpie=chargeWeekDao.getDurationByChargeNameAndDate(lineId, belongYear, startWeek, endWeek, chargew.getChargeName(), "Y");
				if(weekpie!=null){
					Map<String, Object> elePie=new HashMap<String, Object>();
					elePie.put("name", chargew.getChargeName()+"电度");
					elePie.put("value", weekpie.getRelativeComp());
					electricityPie.add(elePie);
					Map<String, Object> charPie=new HashMap<String, Object>();
					charPie.put("name", chargew.getChargeName()+"电费");
					charPie.put("value", weekpie.getCharge());
					chargePie.add(charPie);
				}
	        }
		}
		//设备加和电度和损失电度
		List<Equipment> equs=equipmentDao.listByLine(lineId);
		if(equs.size()!=0){
			for(Equipment e:equs){
				ChargeWeek chargesweeks=chargeWeekDao.getDurationByChargeNameAndDate(e.getId(), belongYear, startWeek, endWeek, "", "N");
				if(chargesweeks!=null){
					machineElectric+=chargesweeks.getRelativeComp();
				}
			}
		}
		model.put("success", true);
		model.put("lineName", lineName);
		model.put("startWeek", belongYear+"年第"+startWeek+"周");
		model.put("endWeek", belongYear+"年第"+endWeek+"周");
		model.put("totalElectric", totalElectric+"度");
		model.put("machineElectric", machineElectric+"度");
		model.put("lossElectric", totalElectric-machineElectric+"度");
		model.put("weeks", weeks);
		model.put("legType", legType);
		model.put("barLegend", barLegend);
		model.put("chargeBar", chargeBar);
		model.put("electricityPie", electricityPie);
		model.put("chargePie", chargePie);
	}
	/**
	 * 整线月电度电费统计
	 * @param lineId
	 * @param belongYear
	 * @param startMonth
	 * @param endMonth
	 * @param model
	 */
	@Override
	public void getLineElecricityMonthData(int lineId, int belongYear, int startMonth, int endMonth, Map<String, Object> model) {
		int totalElectric=0;int machineElectric=0;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
		List<String> legType=new ArrayList<String>();//电度电费峰谷值
		List<String> barLegend=new ArrayList<String>();//legend电度，不同峰谷值
		List<String> months=new ArrayList<String>();//横轴月数
		List<Map<String,Object>> chargeBar=new ArrayList<Map<String,Object>>();//每月不同峰谷值电费
		List<Map<String,Object>> electricityPie=new ArrayList<Map<String,Object>>();//饼图状态电度
		List<Map<String,Object>> chargePie=new ArrayList<Map<String,Object>>();//饼图状态电费
		LineConfig linec=lineConfigDao.get(lineId);
		String lineName=linec.getName()+"("+linec.getLinesNo()+")";
		try {
			String startTime = sdf.format(sdf.parse(belongYear+"-"+startMonth));
			String endTime=sdf.format(sdf.parse(belongYear+"-"+endMonth));
			barLegend.add("电度");
			Map<String, Object> monthcharges=new HashMap<String, Object>();
			List<Integer> monthElecricity=new  ArrayList<Integer>();//每月电度
			for(int month=startMonth;month<=endMonth;month++){
				months.add(month+"月");
				String date = sdf.format(sdf.parse(belongYear+"-"+month));
				ChargeMonth cmonth=chargeMonthDao.getCompByDate(lineId, date, "", "Y");
			    if(cmonth!=null){
			    	monthElecricity.add(cmonth.getRelativeComp().intValue());
			    }
			}
			
	    	monthcharges.put("name", "电度");
	    	monthcharges.put("value", monthElecricity);
	    	chargeBar.add(monthcharges);
	    	
			List<ChargeMonth> chargeNames=chargeMonthDao.getDistinctChargeName(startTime, endTime);
			if(chargeNames.size()!=0){
				for(ChargeMonth c:chargeNames){
					List<Integer> monthCharge=new  ArrayList<Integer>();//每月电费
					//每周各峰谷值电费
		        	barLegend.add(c.getChargeName()+"电费");
		        	monthcharges=new HashMap<String, Object>();
					for(int month=startMonth;month<=endMonth;month++){
						String date=sdf.format(sdf.parse(belongYear+"-"+month));
						ChargeMonth chmon=chargeMonthDao.getCompByDate(lineId, date, c.getChargeName(), "Y");
						if(chmon!=null){
//							monthcharges.put("name", c.getChargeName()+"电费");
//					    	monthcharges.put("value", chmon.getCharge());
//					    	chargeBar.add(monthcharges);
							monthCharge.add(chmon.getCharge().intValue());
						}
					}
					monthcharges.put("name", c.getChargeName()+"电费");
			    	monthcharges.put("value", monthCharge);
			    	chargeBar.add(monthcharges);
					
					//饼图电费电度数据
					legType.add(c.getChargeName()+"电度");
					legType.add(c.getChargeName()+"电费");
					ChargeMonth monthPie=chargeMonthDao.getDurationByChargeNameAndDate(lineId, startTime, endTime, c.getChargeName(), "Y");
				    if(monthPie!=null){
				    	Map<String, Object> elePie=new HashMap<String, Object>();
						elePie.put("name", c.getChargeName()+"电度");
						elePie.put("value", monthPie.getRelativeComp());
						electricityPie.add(elePie);
						Map<String, Object> charPie=new HashMap<String, Object>();
						charPie.put("name", c.getChargeName()+"电费");
						charPie.put("value", monthPie.getCharge());
						chargePie.add(charPie);
				    }
				}
			}
			//电度同比数据
			this.getOnYOYBasisData(lineId, endMonth, model);
			//设备加和电度和损失电度
			List<Equipment> equs=equipmentDao.listByLine(lineId);
			if(equs.size()!=0){
				for(Equipment e:equs){
					ChargeMonth month=chargeMonthDao.getDurationByChargeNameAndDate(e.getId(), startTime, endTime, "", "N");
					if(month!=null){
						machineElectric+=month.getRelativeComp();
					}
				}
			}
			model.put("success", true);
			model.put("lineName", lineName);
			model.put("startTime", startTime);
			model.put("endTime", endTime);
			model.put("totalElectric", totalElectric+"度");
			model.put("machineElectric", machineElectric+"度");
			model.put("lossElectric", totalElectric-machineElectric+"度");
			model.put("months", months);
			model.put("legType", legType);
			model.put("barLegend", barLegend);
			model.put("chargeBar", chargeBar);
			model.put("electricityPie", electricityPie);
			model.put("chargePie", chargePie);
		} catch (ParseException e) {
			e.printStackTrace();
		}	
	}
	/**
	 * 整线电度同比统计
	 * @param lineId
	 * @param belongYear
	 * @param month
	 * @param model
	 */
	public void getOnYOYBasisData(int lineId, int month, Map<String, Object> model){
		List<String> dateLegend =new ArrayList<String>();
		List<Integer> YOYElecricity =new ArrayList<Integer>();
		String belongMonth=""; 
		if(month<10){
			belongMonth="0"+month;
		}else{
			belongMonth=String.valueOf(month);
		}
		//同比的日期
		List<ChargeMonth> months=chargeMonthDao.getdistinctDate(lineId, belongMonth,"Y");
		if(months.size()!=0){
			for(ChargeMonth m:months){
				ChargeMonth cm=chargeMonthDao.getCompByDate(lineId, m.getBelongDate(), "", "Y");
				if(cm!=null){
					dateLegend.add(m.getBelongDate());
					YOYElecricity.add(cm.getRelativeComp().intValue());
				}
			}
		}
		model.put("dateLegend", dateLegend);
		model.put("YOYElecricity", YOYElecricity);
	}
	/**
	 * 整线综合能耗日分析
	 * @param lineId
	 * @param equId
	 * @param belongDate
	 * @param model
	 */
	@Override
	public void getLineCompositeDayData(int lineId,int equId, String belongDate, Map<String, Object> model) {
		int totalElectric=0;int machineElectric=0;
		StringBuffer shiftMode=new StringBuffer();//排班模式
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
		List<String> pieLegend=new ArrayList<String>();//饼图图例
		List<Integer> hourRelativeComp=new ArrayList<Integer>();//每小时电度
		List<Map<String,Object>> electricityPie=new ArrayList<Map<String,Object>>();//饼图电度
		List<Map<String,Object>> chargePie=new ArrayList<Map<String,Object>>();//饼图电费
		LineConfig linec=lineConfigDao.get(lineId);
		String lineName=linec.getName()+"("+linec.getLinesNo()+")";
		//小时字符串
		List<String> hours=Arrays.asList(new String[]{
				"00:30", "01:00", "01:30", "02:00", "02:30", "03:00", "03:30", "04:00", "04:30", "05:00", "05:30", "06:00", "06:30", "07:00", "07:30", "08:00", 
				"08:30", "09:00", "09:30", "10:00", "10:30", "11:00", "11:30", "12:00","12:30", "13:00", "13:30", "14:00", "14:30", "15:00", "15:30", "16:00",
				"16:30", "17:00", "17:30", "18:00", "18:30", "19:00", "19:30", "20:00", "20:30", "21:00", "21:30", "22:00", "22:30", "23:00", "23:30", "24:00"});//getXAxis();
		ShiftConfig  config=shiftConfigDao.findShiftsByLine(lineId, belongDate);//班制
		//班次电度
		if(config!=null){
			List<ShiftConfig> useShifts=shiftConfigDao.findByShiftsId(config.getId());
			if(useShifts.size()!=0){
				for(ShiftConfig s:useShifts){
					shiftMode.append(s.getShiftName()+" ");
				}
			}
		}
		//饼图电度电费
		List<ChargeDay>days=chargeDayDao.getChargeDayIdAndDate(lineId, belongDate, "Y");
		if(days.size()!=0){
			for(ChargeDay day:days){
				pieLegend.add(day.getChargeName()+"电度");
				pieLegend.add(day.getChargeName()+"电费");
				totalElectric+=day.getRelativeComp();
				Map<String,Object> electricMap=new HashMap<String,Object>();
				electricMap.put("name", day.getChargeName()+"电度");
				electricMap.put("value", day.getRelativeComp());
				electricityPie.add(electricMap);
				Map<String,Object> chargeMap=new HashMap<String,Object>();
				chargeMap.put("name", day.getChargeName()+"电费");
				chargeMap.put("value", day.getCharge());
				chargePie.add(chargeMap);
			}
		}else{
			Map<String,Object> electricMap=new HashMap<String,Object>();
			Map<String,Object> chargeMap=new HashMap<String,Object>();
			electricMap.put("name", "电度");
			electricMap.put("value", 0);
			electricityPie.add(electricMap);
			
			chargeMap.put("name", "电费");
			chargeMap.put("value", 0);
			chargePie.add(chargeMap);
		}
		//小时电度
		List<ChargeMin> mins=chargeMinDao.getChargeMinsByDay(lineId, belongDate, "Y");
		int i = 0;
		for(String xt:hours){
			int tempCharge = 0;
			if(i<mins.size()){
				ChargeMin cm = mins.get(i);
				if(sdf.format(cm.getBelongTime()).equals("00:00")){
					i++;
				}else{
					while(sdf.format(cm.getBelongTime()).equals(xt)){
						tempCharge = cm.getRelativeComp().intValue();
						i++;
						break;
					}
				}
			}
			if(tempCharge!=0.0){
				hourRelativeComp.add(tempCharge);
			}else{
				hourRelativeComp.add(0);
			}
		}
		//开动率，满载率折线图
		this.getMachineStartRateDayData(equId, belongDate, model);
		
		//计算设备加和电度和损失电度
		List<Equipment> equs=equipmentDao.listByLine(lineId);
		if(equs.size()!=0){
			for(Equipment e:equs){
				List<ChargeDay>chargesdays=chargeDayDao.getChargeDayIdAndDate(e.getId(), belongDate, "N");
				if(chargesdays.size()!=0){
					for(ChargeDay c:chargesdays){
						machineElectric+=c.getRelativeComp();
					}
				}
			}
		}
		model.put("lineName", lineName);
		model.put("belongDate", belongDate);
		model.put("totalElectric", totalElectric+"度");
		model.put("machineElectric", machineElectric+"度");
		model.put("lossElectric", totalElectric-machineElectric+"度");
		model.put("shiftMode", shiftMode);
		model.put("hours", hours);
		model.put("pieLegend", pieLegend);
		model.put("hourRelativeComp", hourRelativeComp);
		model.put("electricityPie", electricityPie);
		model.put("chargePie", chargePie);
	}
	
	/**
	 * 整线综合能耗日分析——设备开动率
	 * @param equId
	 * @param belongDate
	 * @param model
	 */
	@Override
	public void getMachineStartRateDayData(int equId, String belongDate, Map<String, Object> model) {
		DecimalFormat  df=new DecimalFormat ("0.0");
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
		List<Double>startRate=new ArrayList<Double>();//平均开动率
		List<Double>fullRate=new ArrayList<Double>();//平均满载率
		List<String> hours=Arrays.asList(new String[]{
				"00:30", "01:00", "01:30", "02:00", "02:30", "03:00", "03:30", "04:00", "04:30", "05:00", "05:30", "06:00", "06:30", "07:00", "07:30", "08:00", 
				"08:30", "09:00", "09:30", "10:00", "10:30", "11:00", "11:30", "12:00","12:30", "13:00", "13:30", "14:00", "14:30", "15:00", "15:30", "16:00",
				"16:30", "17:00", "17:30", "18:00", "18:30", "19:00", "19:30", "20:00", "20:30", "21:00", "21:30", "22:00", "22:30", "23:00", "23:30", "24:00"});
	    Equipment equ=equipmentDao.get(equId);
		String  equName=equ.getEquName()+"("+equ.getEquNo()+")";
		List<String> states=Arrays.asList(new String[]{"停机","满载"});
	    for(String state:states){
	    	List<StateMin> mins=stateMinDao.getStateMinsByDay(equId, state, belongDate);
	    	 int i = 0;
	    		for(String xt:hours){
	    			double duration = 0;
	    			if(i<mins.size()){
	    				StateMin sm = mins.get(i);
	    				if(sdf.format(sm.getBelongTime()).equals("00:00")){
	    					i++;
	    				}else{
	    					while(sdf.format(sm.getBelongTime()).equals(xt)){
	    						duration = sm.getDuration();
	    						i++;
	    						break;
	    					}
	    				}
	    			}
	    		if(state.equals("停机")){
	    			if(duration!=0.0){
	    				startRate.add(Double.parseDouble(df.format((1800-duration)/1800*100)));
	    			}else{
	    				startRate.add(0.0);
	    			}
	    		}else{
	      			if(duration!=0.0){
	      				fullRate.add(Double.parseDouble(df.format(duration/1800*100)));
	    			}else{
	    				fullRate.add(0.0);
	    			}
	    		}
	    	}
	    }
	     model.put("equName", equName);
	     model.put("startRateHours", hours);
		 model.put("startRate", startRate);
		 model.put("fullRate", fullRate);
	}
	/**
	 * 整线综合能耗日综合分析
	 * @param lineId
	 * @param equId
	 * @param startDate
	 * @param endDate
	 * @param model
	 */
	@Override
	public void getLineCompositeCompexData(int lineId, int equId, String startDate, String endDate, Map<String, Object> model) {
		int totalElectric=0;int machineElectric=0;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		List<String> legType=new ArrayList<String>();//电费电度峰谷值
		List<String> days=new ArrayList<String>();//横轴天数
		List<Map<String,Object>> electricityBar=new ArrayList<Map<String,Object>>();//每日电度
		
		List<Map<String,Object>> electricityPie=new ArrayList<Map<String,Object>>();//饼图状态电度
		List<Map<String,Object>> chargePie=new ArrayList<Map<String,Object>>();//饼图状态电费
		LineConfig linec=lineConfigDao.get(lineId);
		String lineName=linec.getName()+"("+linec.getLinesNo()+")";
		try {
		    Calendar start=Calendar.getInstance();
		    Calendar end=(Calendar) start.clone();
			start.setTime(sdf.parse(startDate));
			end.setTime(sdf.parse(endDate));
			int aeraDay=(int) ((end.getTimeInMillis()-start.getTimeInMillis())/(24*3600*1000L));
			 //柱状图每日电度
			List<Integer> dayElecricity=new  ArrayList<Integer>();//每天电度值
			for(int day=0;day<=aeraDay;day++){
				String date=sdf.format(new Date(start.getTimeInMillis()+day*24*60*60*1000L));
			    ChargeDay chargeday=chargeDayDao.getCompAndChargeByType(lineId, date, date, "", "Y");
			    if(chargeday!=null){
			    	totalElectric+=chargeday.getRelativeComp();
			    	dayElecricity.add(chargeday.getRelativeComp().intValue());
				}
			    days.add(new SimpleDateFormat("M.d").format(sdf.parse(date)));
			}
			Map<String, Object> dayEle=new HashMap<String, Object>();
			dayEle.put("name", "电度");
			dayEle.put("value", dayElecricity);
			electricityBar.add(dayEle);
			
			//饼图电费电度数据
			List<ChargeDay> chargec=chargeDayDao.getDistricChargeName(lineId, startDate, endDate, "Y");
			if(chargec.size()!=0){
			for(ChargeDay c:chargec){
					legType.add(c.getChargeName()+"电度");
					legType.add(c.getChargeName()+"电费");
					ChargeDay chargeelecricity=chargeDayDao.getCompAndChargeByType(lineId, startDate, endDate, c.getChargeName(), "Y");
					if(chargeelecricity!=null){
						Map<String, Object> elecricitys=new HashMap<String, Object>();
						elecricitys.put("name", c.getChargeName()+"电度");
						elecricitys.put("value", chargeelecricity.getRelativeComp());
						electricityPie.add(elecricitys);
						Map<String, Object> charges=new HashMap<String, Object>();
						charges.put("name", c.getChargeName()+"电费");
						charges.put("value", chargeelecricity.getCharge());
						chargePie.add(charges);
					}
				}
			}
			//设备开动率
			this.getMachineStartRateCompexData(equId, startDate, endDate, model);
			
			//设备加和电度和损失电度
			List<Equipment> equs=equipmentDao.listByLine(lineId);
			if(equs.size()!=0){
				for(Equipment e:equs){
					ChargeDay chargesdays=chargeDayDao.getCompAndChargeByType(e.getId(), startDate, endDate, "", "N");
					if(chargesdays!=null){
						machineElectric+=chargesdays.getRelativeComp();
					}
				}
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		model.put("lineName", lineName);
		model.put("startDate", startDate);
		model.put("endDate", endDate);
		model.put("totalElectric", totalElectric+"度");
		model.put("machineElectric", machineElectric+"度");
		model.put("lossElectric", totalElectric-machineElectric+"度");
		model.put("days", days);
		model.put("electricityBar", electricityBar);
		model.put("legType", legType);
		model.put("electricityPie", electricityPie);
		model.put("chargePie", chargePie);
	}
	/**
	 * 整线综合能耗日综合分析——设备开动率
	 * @param equId
	 * @param startDate
	 * @param endDate
	 * @param model
	 */
	@Override
	public void getMachineStartRateCompexData(int equId, String startDate, String endDate, Map<String, Object> model) {
		DecimalFormat  df=new DecimalFormat ("0.0");
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		List<Double>startRate=new ArrayList<Double>();//平均开动率
		List<Double>fullRate=new ArrayList<Double>();//平均满载率
		List<String> days=new ArrayList<String>();//横轴天数
		List<String> everyday=new ArrayList<String>();//横轴天数
		List<String> states=Arrays.asList(new String[]{"停机","满载"});
		Equipment equ=equipmentDao.get(equId);
		String  equName=equ.getEquName()+"("+equ.getEquNo()+")";
		try {
	        Calendar start=Calendar.getInstance();
	        Calendar end=(Calendar) start.clone();
	        start.setTime(sdf.parse(startDate));
	        end.setTime(sdf.parse(endDate));
			int aeraDay=(int) ((end.getTimeInMillis()-start.getTimeInMillis())/(24*3600*1000L));
		    for(String state:states){
					for(int day=0;day<=aeraDay;day++){
						String date=sdf.format(new Date(start.getTimeInMillis()+day*24*60*60*1000L));
						StateDay sday=stateDayDao.getStateDay(equId, state, date);
						if(sday!=null){
				    		if(state.equals("停机")){
				    				startRate.add(Double.parseDouble(df.format((24-sday.getDuration()/3600)/24*100)));
				    		}else{
				      				fullRate.add(Double.parseDouble(df.format(sday.getDuration()/3600/24*100)));
				    		}
						}else{
					  		if(state.equals("停机")){
			    				startRate.add(0.0);
			    		}else{
			      				fullRate.add(0.0);
			    		}
						}
					    days.add(new SimpleDateFormat("M.d").format(sdf.parse(date)));
					}
			   }
		} catch (ParseException e) {
			e.printStackTrace();
		}
		//日期去重
	    for(String s:days){
	    	 if(Collections.frequency(everyday, s) < 1) everyday.add(s);
	    }
	    model.put("equName", equName);
		model.put("startRateDays", everyday);
		model.put("startRate", startRate);
		model.put("fullRate", fullRate);
	}
	/**
	 * 整线综合能耗周分析
	 * @param lineId
	 * @param belongYear
	 * @param startWeek
	 * @param endWeek
	 * @param model
	 */
	@Override
	public void getLineCompositeWeekData(int lineId,int equId, int belongYear, int startWeek, int endWeek, Map<String, Object> model) {
		int totalElectric=0;int machineElectric=0;
		List<String> legType=new ArrayList<String>();//电度电费峰谷值
		List<String> weeks=new ArrayList<String>();//横轴周数
		List<Map<String,Object>> electricityPie=new ArrayList<Map<String,Object>>();//饼图状态电度
		List<Map<String,Object>> chargePie=new ArrayList<Map<String,Object>>();//饼图状态电费
		LineConfig linec=lineConfigDao.get(lineId);
		String lineName=linec.getName()+"("+linec.getLinesNo()+")";
		//柱状体每周电度
		List<Integer> weekElecricity=new  ArrayList<Integer>();//每周电度
		for(int week=startWeek;week<=endWeek;week++){
			weeks.add(week+"周");
			ChargeWeek cweek=chargeWeekDao.getCompByDate(lineId, belongYear, week, "Y");
			if(cweek!=null){
				weekElecricity.add(cweek.getRelativeComp().intValue());
			}
		}
		//饼图电度电费
		List<ChargeWeek> chargec=chargeWeekDao.getDistinctChargeName(belongYear, startWeek, endWeek);
		if(chargec.size()!=0){
	        for(ChargeWeek chargew:chargec){
				//饼图电费电度数据
				legType.add(chargew.getChargeName()+"电度");
				legType.add(chargew.getChargeName()+"电费");
				ChargeWeek weekpie=chargeWeekDao.getDurationByChargeNameAndDate(lineId, belongYear, startWeek, endWeek, chargew.getChargeName(), "Y");
				if(weekpie!=null){
					Map<String, Object> elePie=new HashMap<String, Object>();
					elePie.put("name", chargew.getChargeName()+"电度");
					elePie.put("value", weekpie.getRelativeComp());
					electricityPie.add(elePie);
					Map<String, Object> charPie=new HashMap<String, Object>();
					charPie.put("name", chargew.getChargeName()+"电费");
					charPie.put("value", weekpie.getCharge());
					chargePie.add(charPie);
				}
	        }
		}
		//设备开动率
		this.getMachineStartRateWeekData(equId, belongYear, startWeek, endWeek, model);
		//设备加和电度和损失电度
		List<Equipment> equs=equipmentDao.listByLine(lineId);
		if(equs.size()!=0){
			for(Equipment e:equs){
				ChargeWeek chargesweeks=chargeWeekDao.getDurationByChargeNameAndDate(e.getId(), belongYear, startWeek, endWeek, "", "N");
				if(chargesweeks!=null){
					machineElectric+=chargesweeks.getRelativeComp();
				}
			}
		}
		model.put("success", true);
		model.put("lineName", lineName);
		model.put("startWeek", belongYear+"年第"+startWeek+"周");
		model.put("endWeek", belongYear+"年第"+endWeek+"周");
		model.put("totalElectric", totalElectric+"度");
		model.put("machineElectric", machineElectric+"度");
		model.put("lossElectric", totalElectric-machineElectric+"度");
		model.put("weeks", weeks);
		model.put("legType", legType);
		model.put("weekElecricity", weekElecricity);
		model.put("electricityPie", electricityPie);
		model.put("chargePie", chargePie);
	}
	/**
	 * 整线综合能耗周分析—设备开动率
	 * @param equId
	 * @param belongYear
	 * @param startWeek
	 * @param endWeek
	 * @param model
	 */
	@Override
	public void getMachineStartRateWeekData(int equId, int belongYear, int startWeek, int endWeek, Map<String, Object> model) {
		DecimalFormat  df=new DecimalFormat ("0.0");
		List<Double>startRate=new ArrayList<Double>();//平均开动率
		List<Double>fullRate=new ArrayList<Double>();//平均满载率
		List<String> weeks=new ArrayList<String>();//横轴周数
		List<String> everyweek=new ArrayList<String>();//横轴周数
		List<String> states=Arrays.asList(new String[]{"停机","满载"});
		Equipment equ=equipmentDao.get(equId);
		String  equName=equ.getEquName()+"("+equ.getEquNo()+")";
		for(String state:states){
			for(int week=startWeek;week<=endWeek;week++){
				StateWeek sweek=stateWeekDao.getStateWeekByStateAndDate(equId, belongYear, week, state);
				if(sweek!=null){
			    		if(state.equals("停机")){
			    				startRate.add(Double.parseDouble(df.format(((7*24-sweek.getDuration()/3600)/(7*24))*100)));
			    		}else{
			      				fullRate.add(Double.parseDouble(df.format(((sweek.getDuration()/3600)/(7*24))*100)));
			    		}
				}else{
					if(state.equals("停机")){
	    				startRate.add(0.0);
	    		}else{
	      				fullRate.add(0.0);
	    		 }
				}
				 weeks.add(week+"周");
			}
		  }
		//周去重
	    for(String s:weeks){
	    	 if(Collections.frequency(everyweek, s) < 1) everyweek.add(s);
	    }
	    model.put("equName", equName);
	    model.put("startRateWeekss", everyweek);
		model.put("startRate", startRate);
		model.put("fullRate", fullRate);
	}
	/**
	 * 整线综合能耗月分析
	 * @param lineId
	 * @param equId
	 * @param belongYear
	 * @param startMonth
	 * @param endMonth
	 * @param model
	 */
	@Override
	public void getLineCompositeMonthData(int lineId, int equId, int belongYear, int startMonth, int endMonth, Map<String, Object> model) {
		int totalElectric=0;int machineElectric=0;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
		List<String> legType=new ArrayList<String>();//电度电费峰谷值
		List<String> months=new ArrayList<String>();//横轴月数
		List<Map<String,Object>> electricityPie=new ArrayList<Map<String,Object>>();//饼图状态电度
		List<Map<String,Object>> chargePie=new ArrayList<Map<String,Object>>();//饼图状态电费
		LineConfig linec=lineConfigDao.get(lineId);
		String lineName=linec.getName()+"("+linec.getLinesNo()+")";
		try {
			//每月电度
			String startTime = sdf.format(sdf.parse(belongYear+"-"+startMonth));
			String endTime=sdf.format(sdf.parse(belongYear+"-"+endMonth));
			List<Integer> monthElecricity=new  ArrayList<Integer>();//每月电度
			for(int month=startMonth;month<=endMonth;month++){
				months.add(month+"月");
				String date = sdf.format(sdf.parse(belongYear+"-"+month));
				ChargeMonth cmonth=chargeMonthDao.getCompByDate(lineId, date, "", "Y");
			    if(cmonth!=null){
			    	monthElecricity.add(cmonth.getRelativeComp().intValue());
			    }
			}
			//饼图电度电费
			List<ChargeMonth> chargeNames=chargeMonthDao.getDistinctChargeName(startTime, endTime);
			if(chargeNames.size()!=0){
				for(ChargeMonth c:chargeNames){
					//饼图电费电度数据
					legType.add(c.getChargeName()+"电度");
					legType.add(c.getChargeName()+"电费");
					ChargeMonth monthPie=chargeMonthDao.getDurationByChargeNameAndDate(lineId, startTime, endTime, c.getChargeName(), "Y");
				    if(monthPie!=null){
				    	Map<String, Object> elePie=new HashMap<String, Object>();
						elePie.put("name", c.getChargeName()+"电度");
						elePie.put("value", monthPie.getRelativeComp());
						electricityPie.add(elePie);
						Map<String, Object> charPie=new HashMap<String, Object>();
						charPie.put("name", c.getChargeName()+"电费");
						charPie.put("value", monthPie.getCharge());
						chargePie.add(charPie);
				    }
				}
			}
			 //设备开动率
		 	 this.getMachineStartRateMonthData(equId, belongYear, startMonth, endMonth, model);
			
			//设备加和电度和损失电度
			List<Equipment> equs=equipmentDao.listByLine(lineId);
			if(equs.size()!=0){
				for(Equipment e:equs){
					ChargeMonth month=chargeMonthDao.getDurationByChargeNameAndDate(e.getId(), startTime, endTime, "", "N");
					if(month!=null){
						machineElectric+=month.getRelativeComp();
					}
				}
			}
			model.put("success", true);
			model.put("lineName", lineName);
			model.put("startTime", startTime);
			model.put("endTime", endTime);
			model.put("totalElectric", totalElectric+"度");
			model.put("machineElectric", machineElectric+"度");
			model.put("lossElectric", totalElectric-machineElectric+"度");
			model.put("months", months);
			model.put("legType", legType);
			model.put("monthElecricity", monthElecricity);
			model.put("electricityPie", electricityPie);
			model.put("chargePie", chargePie);
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}
	/**
	 * 整线综合能耗月分析—设备开动率
	 * @param equId
	 * @param belongYear
	 * @param startMonth
	 * @param endMonth
	 * @param model
	 */
	@Override
	public void getMachineStartRateMonthData(int equId, int belongYear, int startMonth, int endMonth, Map<String, Object> model) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
		DecimalFormat  df=new DecimalFormat ("0.0");
		List<Double>startRate=new ArrayList<Double>();//平均开动率
		List<Double>fullRate=new ArrayList<Double>();//平均满载率
		List<String> months=new ArrayList<String>();//横轴月数
		List<String> everymonth=new ArrayList<String>();//横轴每月数
		List<String> states=Arrays.asList(new String[]{"停机","满载"});
		Equipment equ=equipmentDao.get(equId);
		String  equName=equ.getEquName()+"("+equ.getEquNo()+")";
		try {
			for(String state:states){
				for(int month=startMonth;month<=endMonth;month++){
					Date belongDate=sdf.parse(belongYear+"-"+month);
					String date = sdf.format(belongDate);
					Calendar ca = Calendar.getInstance();  
					ca.setTime(belongDate);
					int totalDay=ca.getActualMaximum(Calendar.DAY_OF_MONTH);
					StateMonth smonth=stateMonthDao.getStateMonthByDate(equId, state, date);
					if(smonth!=null){
				    		if(state.equals("停机")){
				    				startRate.add(Double.parseDouble(df.format(((totalDay*24-smonth.getDuration()/3600)/(totalDay*24))*100)));
				    		}else{
				      				fullRate.add(Double.parseDouble(df.format(((smonth.getDuration()/3600)/(totalDay*24))*100)));
				    		}
					}else{
						if(state.equals("停机")){
		    				startRate.add(0.0);
		    		}else{
		      				fullRate.add(0.0);
		    		}
					}
					months.add(month+"月");
				}
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		//月去重
	    for(String s:months){
	    	 if(Collections.frequency(everymonth, s) < 1) everymonth.add(s);
	    }
	    model.put("equName", equName);
	    model.put("everymonth", everymonth);
		model.put("startRate", startRate);
		model.put("fullRate", fullRate);
	}
	/**
	 * 整线电度损失分析
	 * @param equId
	 * @param belongDate
	 * @param model
	 */
	@Override
	public void getLineElecricityLossData(int equId, String belongDate, Map<String, Object> model) {
		DecimalFormat  df=new DecimalFormat ("0.0");
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat sdft = new SimpleDateFormat("yyyy-MM");
		List<Double>dayStartRate=new ArrayList<Double>();//每日平均开动率
		List<Double>dayFullRate=new ArrayList<Double>();//每日平均满载率
		List<Double>weekStartRate=new ArrayList<Double>();//每周平均开动率
		List<Double>weekFullRate=new ArrayList<Double>();//每周平均满载率
		List<Double>monthStartRate=new ArrayList<Double>();//每月平均开动率
		List<Double>monthFullRate=new ArrayList<Double>();//每月平均满载率
		
		List<String> days=new ArrayList<String>();//横轴天数
		List<String> weeks=new ArrayList<String>();//横轴周数
		List<String> months=new ArrayList<String>();//横轴月数
		
		List<String> everyday=new ArrayList<String>();//横轴天数
		List<String> everyweek=new ArrayList<String>();//横轴周数
		List<String> everymonth=new ArrayList<String>();//横轴月数
		
		List<String> states=Arrays.asList(new String[]{"停机","满载"});
		Equipment equ=equipmentDao.get(equId);
		String  equName=equ.getEquName()+"("+equ.getEquNo()+")";
		try {
			Calendar endDay=Calendar.getInstance();
			Date date=sdf.parse(belongDate);
			endDay.setTime(date);
			Calendar startDay=(Calendar)endDay.clone();
			startDay.add(Calendar.DAY_OF_YEAR, -6);
			  for(String state:states){
				  //每日开动率 满载率
				for(int day=0;day<=6;day++){
					String bdate=sdf.format(new Date(startDay.getTimeInMillis()+day*24*60*60*1000L));
					StateDay sday=stateDayDao.getStateDay(equId, state, bdate);
					if(sday!=null){
			    		if(state.equals("停机")){
			    				dayStartRate.add(Double.parseDouble(df.format((24-sday.getDuration()/3600)/24*100)));
			    		}else{
			      				dayFullRate.add(Double.parseDouble(df.format(sday.getDuration()/3600/24*100)));
			    		}
					}else{
				  		if(state.equals("停机")){
				  			dayStartRate.add(0.0);
		    		}else{
		    			dayFullRate.add(0.0);
		    		}
					}
				    days.add(new SimpleDateFormat("M.d").format(sdf.parse(bdate)));
				}
				//每周开动率，满载率
				Calendar endWeek=Calendar.getInstance();
				endWeek.setFirstDayOfWeek(Calendar.MONDAY);
				endWeek.setTime(date);
				Calendar startWeek=(Calendar)endWeek.clone();
				startWeek.add(Calendar.WEEK_OF_YEAR, -6);
				for(int week=0;week<=6;week++){
					int byear=startWeek.get(Calendar.YEAR);
					int bweek=startWeek.get(Calendar.WEEK_OF_YEAR);
						StateWeek sweek=stateWeekDao.getStateWeekByStateAndDate(equId, byear, bweek, state);
						if(sweek!=null){
					    		if(state.equals("停机")){
					    				weekStartRate.add(Double.parseDouble(df.format(((7*24-sweek.getDuration()/3600)/(7*24))*100)));
					    		}else{
					      				weekFullRate.add(Double.parseDouble(df.format(((sweek.getDuration()/3600)/(7*24))*100)));
					    		}
						   
						}else{
							if(state.equals("停机")){
								weekStartRate.add(0.0);
			    		}else{
			    			weekFullRate.add(0.0);
			    		 }
						}
					weeks.add(bweek+"周");
					startWeek.add(Calendar.WEEK_OF_YEAR, 1);
				}
				//每月开动率 满载率
				Calendar endMonth=Calendar.getInstance();
				endMonth.setTime(date);
				Calendar startMonth=(Calendar) endMonth.clone();
				startMonth.add(Calendar.MONTH, -6);
				for(int month=0;month<=6;month++){
					String bdate = sdft.format(startMonth.getTime());
					Calendar cal = Calendar.getInstance();  
					cal.setTime(sdft.parse(bdate));
					int totalDay=cal.getActualMaximum(Calendar.DAY_OF_MONTH);
					StateMonth smonth=stateMonthDao.getStateMonthByDate(equId, state, bdate);
					if(smonth!=null){
				    		if(state.equals("停机")){
				    				monthStartRate.add(Double.parseDouble(df.format(((totalDay*24-smonth.getDuration()/3600)/(totalDay*24))*100)));
				    		}else{
				      				monthFullRate.add(Double.parseDouble(df.format(((smonth.getDuration()/3600)/(totalDay*24))*100)));
				    		}
					}else{
						if(state.equals("停机")){
							monthStartRate.add(0.0);
		    		}else{
		    			monthFullRate.add(0.0);
		    		}
					}
					startMonth.add(Calendar.MONTH, 1);
					months.add(startMonth.get(Calendar.MONTH)+"月");
				}
			  }
		} catch (ParseException e) {
			e.printStackTrace();
		}
		//日期去重
	    for(String s:days){
	    	 if(Collections.frequency(everyday, s) < 1) everyday.add(s);
	    }
		//周去重
	    for(String s:weeks){
	    	 if(Collections.frequency(everyweek, s) < 1) everyweek.add(s);
	    }
		//月去重
	    for(String s:months){
	    	 if(Collections.frequency(everymonth, s) < 1) everymonth.add(s);
	    }
		
		model.put("equName", equName);
		model.put("everyday", everyday);
		model.put("dayStartRate", dayStartRate);
		model.put("dayFullRate", dayFullRate);
		model.put("everyweek", everyweek);
		model.put("weekStartRate", weekStartRate);
		model.put("weekFullRate", weekFullRate);	
		model.put("everymonth", everymonth);
		model.put("monthStartRate", monthStartRate);
		model.put("monthFullRate", monthFullRate);		
	}
	/**
	 * 整线平均开动率日分析
	 * @param lineId
	 * @param equId
	 * @param belongDate
	 * @param model
	 */
	@Override
	public void getAverageStartRateDayData(int lineId, int equId, String belongDate, Map<String, Object> model) {
		DecimalFormat  df=new DecimalFormat ("0.0");
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
		int totalElectric=0;String lowTime="";double lowAverageStartRate=0.0;String lowMachine="";double lowStartRate=0.0;
		String highTime="";double highAverageStartRate=0.0;String highMachine="";double highStartRate=0.0;
		List<String> hourEqu=new ArrayList<String>();
		List<String> lowBelongTime=new ArrayList<String>();
		List<String> highBelongTime=new ArrayList<String>();
		List<Double> lowHourDuration=new ArrayList<Double>();
		List<Double> highHourDuration=new ArrayList<Double>();
		List<Integer> equIds=new ArrayList<Integer>();
		ChargeDay cd=chargeDayDao.getCompAndChargeByType(lineId,belongDate,belongDate,"","Y");
		if(cd!=null){
			totalElectric=cd.getRelativeComp().intValue();
		}
		LineConfig linec=lineConfigDao.get(lineId);
		String lineName=linec.getName()+"("+linec.getLinesNo()+")";
		List<Equipment> equs=equipmentDao.listByLine(lineId);
		if(equs.size()!=0){
			for(Equipment e:equs){
				//此处stateType应使用“停机”  由于停机数据都为0  暂时用"待机"  
				List<StateMin> lowSm=stateMinDao.getDurationByStateType(e.getId(), "待机", belongDate, "Y");
				//如果有多台设备设备停机时间相同 暂时取第一台设备的值
				if(lowSm.size()!=0){
					lowHourDuration.add(lowSm.get(0).getDuration());
					lowBelongTime.add(sdf.format(lowSm.get(0).getBelongTime()));
				}else{
					lowHourDuration.add(0.0);
					lowBelongTime.add("");
				}
				//如果有多台设备设备停机时间相同 暂时取第一台设备的值
				List<StateMin> highSm=stateMinDao.getDurationByStateType(e.getId(), "待机", belongDate, "N");
				if(highSm.size()!=0){
					highHourDuration.add(highSm.get(0).getDuration());
					highBelongTime.add(sdf.format(highSm.get(0).getBelongTime()));
				}else{
					highHourDuration.add(0.0);
					highBelongTime.add("");
				}
				hourEqu.add(e.getEquName()+"("+e.getEquNo()+")");
				equIds.add(e.getId());
			}
		}
		//最高效设备 开动率 平均开动率
		double lowHour=lowHourDuration.get(0);
		int lowIndex=0;
		for(int i=0;i<lowHourDuration.size();i++){
			if(lowHourDuration.get(i)<lowHour){
				lowIndex=i;
				lowHour=lowHourDuration.get(i);
			}
		}
		lowMachine=hourEqu.get(lowIndex);
		lowTime=lowBelongTime.get(lowIndex);
		int lowEquId=equIds.get(lowIndex);
		if(lowHour!=0.0){
			lowStartRate=Double.parseDouble(df.format((1800-lowHour)/1800*100));
		}
		StateDay lowsd=stateDayDao.getStateDay(lowEquId, "待机", belongDate);
		if(lowsd!=null){
			lowAverageStartRate=Double.parseDouble(df.format((24*3600-lowsd.getDuration())/(24*3600)*100));
		}
		
		 //最低效设备 开动率 平均开动率
		 double highHour=highHourDuration.get(0);
		 int highIndex=0;
		 for(int j=0;j<highHourDuration.size();j++){
				if(highHourDuration.get(j)>highHour){
					highIndex=j;
					highHour=highHourDuration.get(j);
				}
		 }
		 highMachine=hourEqu.get(highIndex);
		 highTime=highBelongTime.get(highIndex);
		 int highEquId=equIds.get(highIndex);
		 if(highHour!=0.0){
			highStartRate=Double.parseDouble(df.format((1800-highHour)/1800*100));
		 }
		 StateDay highsd=stateDayDao.getStateDay(highEquId, "待机", belongDate);
		 if(highsd!=null){
			highAverageStartRate=Double.parseDouble(df.format((24*3600-highsd.getDuration())/(24*3600)*100));
		 }
		//每小时平均开动率 满载率
		this.getMachineStartRateDayData(equId, belongDate, model);
		model.put("lineName", lineName);
		model.put("belongDate", belongDate);
		model.put("totalElectric", totalElectric+"度");
		model.put("highTime", highTime);
		model.put("highAverageStartRate", highAverageStartRate+"%");
		model.put("highMachine", highMachine);
		model.put("highStartRate", highStartRate+"%");
		
		model.put("lowTime", lowTime);
		model.put("lowAverageStartRate", lowAverageStartRate+"%");
		model.put("lowMachine", lowMachine);
		model.put("lowStartRate", lowStartRate+"%");
	}
	/**
	 * 整线平均开动率日综合分析
	 * @param lineId
	 * @param equId
	 * @param startDate
	 * @param endDate
	 * @param model
	 */
	@Override
	public void getAverageStartRateCompositeData(int lineId, int equId, String startDate, String endDate, Map<String, Object> model) {
		DecimalFormat  df=new DecimalFormat ("0.0");
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		int totalElectric=0;String lowTime="";double lowAverageStartRate=0.0;String lowMachine="";double lowStartRate=0.0;
		String highTime="";double highAverageStartRate=0.0;String highMachine="";double highStartRate=0.0;
		List<String> days=new ArrayList<String>();
		List<String> equNames=new ArrayList<String>();
		List<Double> machineDuration=new ArrayList<Double>();
		List<Integer> equIds=new ArrayList<Integer>();
		List<Equipment> equs=equipmentDao.listByLine(lineId);
		LineConfig linec=lineConfigDao.get(lineId);
		String lineName=linec.getName()+"("+linec.getLinesNo()+")";
	    try {
	    	Calendar start=Calendar.getInstance();
			Calendar end=(Calendar) start.clone();
			start.setTime(sdf.parse(startDate));
			end.setTime(sdf.parse(endDate));
			int aeraDay=(int) ((end.getTimeInMillis()-start.getTimeInMillis())/(24*3600*1000L));
			for(int day=0;day<=aeraDay;day++){
				String date=sdf.format(new Date(start.getTimeInMillis()+day*24*60*60*1000L));
			    ChargeDay chargeday=chargeDayDao.getCompAndChargeByType(lineId, date, date, "", "Y");
			    if(chargeday!=null){
			    	totalElectric+=chargeday.getRelativeComp().intValue();
				}
			    if(equs.size()!=0){
			    	for(Equipment e:equs){
			    		//此处stateType应使用“停机”  由于停机数据都为0  暂时用"待机"  
			    		StateDay sd=stateDayDao.getStateDay(e.getId(), "待机", date);
			    		if(sd!=null){
			    			machineDuration.add(sd.getDuration());
			    		}else{
			    			machineDuration.add(0.0);
			    		}
			    		equIds.add(e.getId());
			    		equNames.add(e.getEquName()+"("+e.getEquNo()+")");
			    		days.add(date);
			    	}
			    }
			}
			//找出最大停机时长和最小停机时长
			int maxIndex=0; int minIndex=0;
			double maxDuration=machineDuration.get(0); double minDuration=machineDuration.get(0); 
			for(int i=0;i<machineDuration.size();i++){
				if(maxDuration<machineDuration.get(i)){
					maxDuration=machineDuration.get(i);
					maxIndex=i;
				}
				if(minDuration>machineDuration.get(i)){
					minDuration=machineDuration.get(i);
					minIndex=i;
				}
			}
			//计算最高效设备和开动率
			lowMachine=equNames.get(minIndex);
			lowTime=days.get(minIndex);
			lowAverageStartRate=Double.parseDouble(df.format((24*3600-machineDuration.get(minIndex))/(24*3600)*100));
			int lowEquId=equIds.get(minIndex);
			//此处stateType应使用“停机”  由于停机数据都为0  暂时用"待机"  
			double lowDuration=stateDayDao.getTotalWorkTime(lowEquId, startDate, endDate, "待机");
			lowStartRate=Double.parseDouble(df.format((aeraDay*24*3600-lowDuration)/(aeraDay*24*3600)*100));
			
			//计算最低效设备和开动率
			highMachine=equNames.get(maxIndex);
			highTime=days.get(maxIndex);
			highAverageStartRate=Double.parseDouble(df.format((24*3600-machineDuration.get(maxIndex))/(24*3600)*100));
			int highEquId=equIds.get(maxIndex);
			//此处stateType应使用“停机”  由于停机数据都为0  暂时用"待机"  
			double highDuration=stateDayDao.getTotalWorkTime(highEquId, startDate, endDate, "待机");
			highStartRate=Double.parseDouble(df.format((aeraDay*24*3600-highDuration)/(aeraDay*24*3600)*100));
			
			//平均开动率 满载率
			this.getMachineStartRateCompexData(equId, startDate, endDate, model);
			
			model.put("lineName", lineName);
			model.put("startDate", startDate);
			model.put("endDate", endDate);
			model.put("totalElectric", totalElectric+"度");
			model.put("lowMachine", lowMachine);
			model.put("lowTime", lowTime);
			model.put("lowAverageStartRate", lowAverageStartRate+"%");
			model.put("lowStartRate", lowStartRate+"%");
			
			model.put("highMachine", highMachine);
			model.put("highTime", highTime);
			model.put("highAverageStartRate", highAverageStartRate+"%");
			model.put("highStartRate", highStartRate+"%");
			
			
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}
    /**
     * 整线平均开动率周分析
     * @param lineId
     * @param equId
     * @param belongYear
     * @param startWeek
     * @param endWeek
     * @param model
     */
	@Override
	public void getAverageStartRateWeekData(int lineId, int equId, int belongYear, int startWeek, int endWeek, Map<String, Object> model) {
		DecimalFormat  df=new DecimalFormat ("0.0");
		int totalElectric=0;String lowTime="";double lowAverageStartRate=0.0;String lowMachine="";double lowStartRate=0.0;
		String highTime="";double highAverageStartRate=0.0;String highMachine="";double highStartRate=0.0;
		List<String> weeks=new ArrayList<String>();
		List<String> equNames=new ArrayList<String>();
		List<Double> machineDuration=new ArrayList<Double>();
		List<Integer> equIds=new ArrayList<Integer>();
		List<Equipment> equs=equipmentDao.listByLine(lineId);
		LineConfig linec=lineConfigDao.get(lineId);
		String lineName=linec.getName()+"("+linec.getLinesNo()+")";
		
		for(int week=startWeek;week<=endWeek;week++){
			ChargeWeek cweek=chargeWeekDao.getCompByDate(lineId, belongYear, week, "Y");
			if(cweek!=null){
				totalElectric+=cweek.getRelativeComp().intValue();
			}
			if(equs.size()!=0){
		    	for(Equipment e:equs){
		    		//此处stateType应使用“停机”  由于停机数据都为0  暂时用"待机"
		    		StateWeek sw=stateWeekDao.getStateWeekByStateAndDate(e.getId(), belongYear, week, "待机");
		    		if(sw!=null){
		    			machineDuration.add(sw.getDuration());
		    		}else{
		    			machineDuration.add(0.0);
		    		}
		    		equIds.add(e.getId());
		    		equNames.add(e.getEquName()+"("+e.getEquNo()+")");
		    		weeks.add(week+"周");
		    	}
			}
	   }
		//找出最大停机时长和最小停机时长
		int maxIndex=0; int minIndex=0;
		double maxDuration=machineDuration.get(0); double minDuration=machineDuration.get(0); 
		for(int i=0;i<machineDuration.size();i++){
			if(maxDuration<machineDuration.get(i)){
				maxDuration=machineDuration.get(i);
				maxIndex=i;
			}
			if(minDuration>machineDuration.get(i)){
				minDuration=machineDuration.get(i);
				minIndex=i;
			}
		}
		//计算最高效设备和开动率
		lowMachine=equNames.get(minIndex);
		lowTime=weeks.get(minIndex);
		lowAverageStartRate=Double.parseDouble(df.format((7*24*3600-machineDuration.get(minIndex))/(7*24*3600)*100));
		int lowEquId=equIds.get(minIndex);
		//此处stateType应使用“停机”  由于停机数据都为0  暂时用"待机"  
		StateWeek lowSw=stateWeekDao.getdurationByStateAndDate(lowEquId, belongYear, startWeek, endWeek, "待机");
		if(lowSw!=null){
			double lowDuration=lowSw.getDuration();
			lowStartRate=Double.parseDouble(df.format(((endWeek-startWeek)*7*24*3600-lowDuration)/((endWeek-startWeek)*7*24*3600)*100));
		}
		//计算最低效设备和开动率
		highMachine=equNames.get(maxIndex);
		highTime=weeks.get(maxIndex);
		highAverageStartRate=Double.parseDouble(df.format((7*24*3600-machineDuration.get(maxIndex))/(7*24*3600)*100));
		int highEquId=equIds.get(maxIndex);
		//此处stateType应使用“停机”  由于停机数据都为0  暂时用"待机"  
		StateWeek highSw=stateWeekDao.getdurationByStateAndDate(highEquId, belongYear, startWeek, endWeek, "待机");
		if(highSw!=null){
			double highDuration=highSw.getDuration();
			highStartRate=Double.parseDouble(df.format(((endWeek-startWeek)*7*24*3600-highDuration)/((endWeek-startWeek)*7*24*3600)*100));
		}
		
		//平均开动率 满载率
		this.getMachineStartRateWeekData(equId, belongYear, startWeek, endWeek, model);
		
		model.put("lineName", lineName);
		model.put("startWeek", belongYear+"年第"+startWeek+"周");
		model.put("endWeek", belongYear+"年第"+endWeek+"周");
		model.put("totalElectric", totalElectric+"度");
		model.put("lowMachine", lowMachine);
		model.put("lowTime", belongYear+"年第"+lowTime);
		model.put("lowAverageStartRate", lowAverageStartRate+"%");
		model.put("lowStartRate", lowStartRate+"%");
		
		model.put("highMachine", highMachine);
		model.put("highTime", belongYear+"年第"+highTime);
		model.put("highAverageStartRate", highAverageStartRate+"%");
		model.put("highStartRate", highStartRate+"%");
	}
	/**
	 * 整线平均开动率月分析
	 * @param lineId
	 * @param equId
	 * @param belongYear
	 * @param startMonth
	 * @param endMonth
	 * @param model
	 */
	@Override
	public void getAverageStartRateMonthData(int lineId, int equId, int belongYear, int startMonth, int endMonth, Map<String, Object> model) {
		DecimalFormat  df=new DecimalFormat ("0.0");
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
		int areaDays=0;int totalElectric=0;String lowTime="";double lowAverageStartRate=0.0;String lowMachine="";double lowStartRate=0.0;
		String highTime="";double highAverageStartRate=0.0;String highMachine="";double highStartRate=0.0;
		List<String> months=new ArrayList<String>();
		List<String> equNames=new ArrayList<String>();
		List<Double> machineDuration=new ArrayList<Double>();
		List<Integer> equIds=new ArrayList<Integer>();
		List<Integer> totalDays=new ArrayList<Integer>();
		List<Equipment> equs=equipmentDao.listByLine(lineId);
		LineConfig linec=lineConfigDao.get(lineId);
		String lineName=linec.getName()+"("+linec.getLinesNo()+")";
		try {
			String startTime = sdf.format(sdf.parse(belongYear+"-"+startMonth));
			String endTime=sdf.format(sdf.parse(belongYear+"-"+endMonth));
			for(int month=startMonth;month<=endMonth;month++){
				Date belongDate=sdf.parse(belongYear+"-"+month);
				String date = sdf.format(belongDate);
				Calendar ca = Calendar.getInstance();  
				ca.setTime(belongDate);
				areaDays+=ca.getActualMaximum(Calendar.DAY_OF_MONTH);
				ChargeMonth cm=chargeMonthDao.getCompByDate(lineId, date, "", "Y");
			    if(cm!=null){
			    	totalElectric+=cm.getRelativeComp().intValue();
			    }
			    if(equs.size()!=0){
			    	for(Equipment e:equs){
			    		//此处stateType应使用“停机”  由于停机数据都为0  暂时用"待机"
			    		StateMonth sm=stateMonthDao.getStateMonthByDate(e.getId(), "待机", date);
			    		if(sm!=null){
			    			machineDuration.add(sm.getDuration());
			    		}else{
			    			machineDuration.add(0.0);
			    		}
			    		//每月总天数
			    		totalDays.add(ca.getActualMaximum(Calendar.DAY_OF_MONTH));
					    equIds.add(e.getId());
			    		equNames.add(e.getEquName()+"("+e.getEquNo()+")");
					    months.add(month+"月");
			    		}
			    	}
			}
			//找出最大停机时长和最小停机时长
			int maxIndex=0; int minIndex=0;
			double maxDuration=machineDuration.get(0); double minDuration=machineDuration.get(0); 
			for(int i=0;i<machineDuration.size();i++){
				if(maxDuration<machineDuration.get(i)){
					maxDuration=machineDuration.get(i);
					maxIndex=i;
				}
				if(minDuration>machineDuration.get(i)){
					minDuration=machineDuration.get(i);
					minIndex=i;
				}
			}
			//计算最高效设备和开动率
			int lowDays=totalDays.get(minIndex);
			lowMachine=equNames.get(minIndex);
			lowTime=months.get(minIndex);
			lowAverageStartRate=Double.parseDouble(df.format((lowDays*24*3600-machineDuration.get(minIndex))/(lowDays*24*3600)*100));
			int lowEquId=equIds.get(minIndex);
			//此处stateType应使用“停机”  由于停机数据都为0  暂时用"待机"  
			double lowDuration=stateMonthDao.getTotalWorkTime(lowEquId, startTime, endTime, "待机");
			lowStartRate=Double.parseDouble(df.format((areaDays*24*3600-lowDuration)/(areaDays*24*3600)*100));
			
			//计算最低效设备和开动率
			int highDays=totalDays.get(maxIndex);
			highMachine=equNames.get(maxIndex);
			highTime=months.get(maxIndex);
			highAverageStartRate=Double.parseDouble(df.format((highDays*24*3600-machineDuration.get(maxIndex))/(highDays*24*3600)*100));
			int highEquId=equIds.get(maxIndex);
			//此处stateType应使用“停机”  由于停机数据都为0  暂时用"待机"  
			double highDuration=stateMonthDao.getTotalWorkTime(highEquId, startTime, endTime, "待机");
			highStartRate=Double.parseDouble(df.format((areaDays*24*3600-highDuration)/(areaDays*24*3600)*100));
		
			//平均开动率 满载率
			this.getMachineStartRateMonthData(equId, belongYear, startMonth, endMonth, model);
			
			//开动率 满载率 月同比
			this.getOnYOYStartRateData(equId, startMonth, model);
			
			model.put("lineName", lineName);
			model.put("startMonth", belongYear+"年"+startMonth+"月");
			model.put("endMonth", belongYear+"年"+endMonth+"月");
			model.put("totalElectric", totalElectric+"度");
			model.put("lowMachine", lowMachine);
			model.put("lowTime", belongYear+"年"+lowTime);
			model.put("lowAverageStartRate", lowAverageStartRate+"%");
			model.put("lowStartRate", lowStartRate+"%");
			
			model.put("highMachine", highMachine);
			model.put("highTime", belongYear+"年"+highTime);
			model.put("highAverageStartRate", highAverageStartRate+"%");
			model.put("highStartRate", highStartRate+"%");
		
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}
    /**
     * 获取整线开动率 满载率月度同比数据
     * @param equId
     * @param month
     * @param model
     */
	@Override
	public void getOnYOYStartRateData(int equId, int month, Map<String, Object> model) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
		DecimalFormat  df=new DecimalFormat ("0.0");
		List<Double>startRates=new ArrayList<Double>();//平均开动率
		List<Double>fullRates=new ArrayList<Double>();//平均满载率
		List<String> months=new ArrayList<String>();//横轴月数
		List<String> everymonths=new ArrayList<String>();//横轴每月数
		List<String> states=Arrays.asList(new String[]{"停机","满载"});
		Equipment equ=equipmentDao.get(equId);
		String  equName=equ.getEquName()+"("+equ.getEquNo()+")";
		try{
				String belongMonth=""; 
				if(month<10){
					belongMonth="0"+month;
				}else{
					belongMonth=String.valueOf(month);
				}
				List<StateMonth> smonths=stateMonthDao.getBySameMonth(equId, belongMonth, "停机");
				for(String state:states){
			    	if(smonths.size()!=0){
						for(StateMonth m:smonths){
							String date = m.getBelongDate();
							Calendar ca = Calendar.getInstance();  
							ca.setTime(sdf.parse(date));
							int totalDay=ca.getActualMaximum(Calendar.DAY_OF_MONTH);
							StateMonth smonth=stateMonthDao.getStateMonthByDate(equId, state, date);
							if(smonth!=null){
						    		if(state.equals("停机")){
						    				startRates.add(Double.parseDouble(df.format(((totalDay*24-smonth.getDuration()/3600)/(totalDay*24))*100)));
						    		}else{
						      				fullRates.add(Double.parseDouble(df.format(((smonth.getDuration()/3600)/(totalDay*24))*100)));
						    		}
							}else{
								if(state.equals("停机")){
				    				startRates.add(0.0);
				    		}else{
				      				fullRates.add(0.0);
				    		}
							}
							months.add(m.getBelongDate());
						}
			    	}
			    }
			} catch (ParseException e) {
		        e.printStackTrace();
	   }
		//月去重
	    for(String s:months){
	    	 if(Collections.frequency(everymonths, s) < 1) everymonths.add(s);
	    }
	    model.put("equName", equName);
	    model.put("everymonths", everymonths);
		model.put("startRates", startRates);
		model.put("fullRates", fullRates);	
 }
}
